import axios from "axios";

const service = axios.create({
  baseURL: "http://localhost:9999/item",
  timeout: 10000,
});

// 请求拦截器
service.interceptors.request.use(
  (config) => {
    config.headers.icode = "input you icode";
    return config; // 必须返回配置
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
service.interceptors.response.use((response) => {
  // console.log(response.data);
  const { code, msg, data } = response.data;
  //   要根据success的成功与否决定下面的操作
  if (code === 200) {
    console.log(data.storeInfo);
    return data;
  } else {
    return Promise.reject(new Error(msg));
  }
});

export default service;
